// import 'babel-polyfill'
import Vue from 'vue'
import App from './App.vue'
import {
  Button,
  Cell,
  CellGroup,
  Field,
  Radio,
  RadioGroup,
  Toast
} from 'vant'
import VueRouter from 'vue-router'
import localstorage from 'store'
import Index from './pages/index'
import Question from './pages/Question'
import Result from './pages/Result'
import utils from './utils'
// import Bmob from "hydrogen-js-sdk";

// Bmob.initialize("89bc009290422e75e7ab6e51971617eb", "fd586909cf60b33bb27342d9877e10d4");

const routes = [{
    path: '/',
    component: Index
  },
  {
    path: '/question',
    component: Question
  },
  {
    path: '/result',
    component: Result
  }
]
const router = new VueRouter({
  routes
})

//微信登录 返回微信个人信息：昵称头像openid
const weixinInfo = utils.weixinLogin()
//微信个人信息 存储本地
localstorage.set('weixinInfo', weixinInfo)

router.beforeEach((to, from, next) => {

  const userInfo = localstorage.get('userInfo');
  const scoreInfo = localstorage.get('scoreInfo');
  next();
  if (!userInfo) next('/');
  else if (!scoreInfo) next('/question');
  else if (scoreInfo.score !== null) next('/result');
  else next('/question');

  // next('/result) 停止活动
})
Vue.config.productionTip = false

Vue.use(VueRouter)
Vue.use(Button)
Vue.use(Cell)
Vue.use(CellGroup)
Vue.use(Field)
Vue.use(Radio)
Vue.use(RadioGroup)
Vue.use(Toast)
// Vue.prototype.bmob = Bmob

new Vue({
  render: h => h(App),
  router
}).$mount('#app')